﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxEditors;
using DAL;

public partial class ProExecute : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Frame.Global.GlobalFunctions.SetGridView(gvPro, true);
        Frame.Global.GlobalFunctions.InitComboBoxColumn(gvPro.Columns["t_ProID"], "ProjectDetails", "Project_Name", "Project_ID");
        gvPro.SettingsText.PopupEditFormCaption = "编辑";
        try
        {
            if (!CMSUser.Current.IsLogin)
            {
                Response.Redirect("~/Login.aspx");
            }
        }
        catch (Exception)
        {
            Response.Redirect("~/Login.aspx");
        }
        string username = CMSUser.Current.Name;
        if (!username.Equals("Administrator"))
        {
            this.gvPro.SettingsText.CommandDelete = "";
            GridViewCommandColumn column = (GridViewCommandColumn)gvPro.Columns["inputcmdcol"];
            column.DeleteButton.Visible = false;
        }
    }


    protected void LSMDSPro_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
    {
        DAL.DataClassesDataContext dc = new DAL.DataClassesDataContext();
        e.QueryableSource = dc.Pro_Execute.Where(p => p.ProID == Request.QueryString["id"].ToString());
    }

    TableRow row = new TableRow();
    protected void gvPro_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
    {
        int rowindex = e.VisibleIndex;
        if (rowindex == 0)
        {
            row = e.Row;
        }
        if (rowindex - 1 < 0) return;

        int id = Convert.ToInt32(gvPro.GetRowValues(rowindex - 1, "ProID").ToString());
        if (Convert.ToInt32(e.GetValue("ProID").ToString()) == id)
        {
            if (row.Cells[0].RowSpan == 0)
                row.Cells[0].RowSpan++;
            row.Cells[0].RowSpan++;
            e.Row.Cells[0].Visible = false;
        }
        else
        {
            row = e.Row;
        }
    }

    protected void gvPro_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        e.NewValues["ProID"] = Request.QueryString["id"];
        e.NewValues["ID"] = DateTime.Now.ToString("yyyyMMddHHmmssff");
    }
}